package IC.lir;

import java.util.LinkedHashMap;
import java.util.Map;
import IC.Constants;

/**
 * 
 * LIRProgram Object
 *
 */
public class LIRProgram extends LIRObject {

	private Map<String,LIRStringLiteral> Sl; 
	private Map<String,LIRClass> Classes;
	
	
	//C'tor
	public LIRProgram(){
		super();
		Sl = new LinkedHashMap<String,LIRStringLiteral>();
		Sl.put(LIRConstants.str1,new LIRStringLiteral(LIRConstants.str1));
		Sl.put(LIRConstants.str2,new LIRStringLiteral(LIRConstants.str2));
		Sl.put(LIRConstants.str3,new LIRStringLiteral(LIRConstants.str3));
		Sl.put(LIRConstants.str4,new LIRStringLiteral(LIRConstants.str4));
		Classes = new LinkedHashMap<String,LIRClass>();
	}
	
	public Map<String,LIRClass> getClasses() {
		return Classes;
	}
	
	public LIRStringLiteral getStringLiteral(String str) {
		if (!Sl.containsKey(str))
			Sl.put(str, new LIRStringLiteral(str));
		return Sl.get(str);	
	}
	
	@Override
	public String toString() {
		StringBuffer s = new StringBuffer();
		
		s.append("### Program StringLiterals ###"+ Constants.LINE_BREAK);
		for (LIRStringLiteral sl : Sl.values())
			s.append(sl + Constants.LINE_BREAK);
		
		s.append(Constants.LINE_BREAK);
		for (LIRClass c : Classes.values()) {
			s.append("### Class " + c.getName() +" Layout ###"+ Constants.LINE_BREAK);
			s.append(c.getClassLayout()+ Constants.LINE_BREAK);
		}
		
		for (LIRClass c : Classes.values())
			s.append(c + Constants.LINE_BREAK);
		return s.toString();
	}
}
